
package com.treeman.navi.map;

import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;

import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;


public class MapGestureOverlay extends Overlay implements OnGestureListener
{

    private GestureDetector gestureDetector;
    private OnGestureListener onGestureListener;


    public MapGestureOverlay()
    {
	gestureDetector = new GestureDetector(this);
    }

    public MapGestureOverlay(OnGestureListener onGestureListener)
    {
	this();
	setOnGestureListener(onGestureListener);
    }

    @Override
    public boolean onTouchEvent(MotionEvent e, MapView mapView)
    {
	if (gestureDetector.onTouchEvent(e))
	{
	    return true;
	}
	return false;
	// return super.onTouchEvent(e, mapView);
    }

    @Override
    public boolean onDown(MotionEvent e)
    {
	if (onGestureListener != null)
	{
	    return onGestureListener.onDown(e);
	}
	return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    {
	if (onGestureListener != null)
	{
	    return onGestureListener.onFling(e1, e2, velocityX, velocityY);
	}
	return false;
    }

    @Override
    public void onLongPress(MotionEvent e)
    {
	if (onGestureListener != null)
	{
	    onGestureListener.onLongPress(e);
	}

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
    {
	if (onGestureListener != null)
	{
	    onGestureListener.onScroll(e1, e2, distanceX, distanceY);
	}
	return false;
    }

    @Override
    public void onShowPress(MotionEvent e)
    {
	if (onGestureListener != null)
	{
	    onGestureListener.onShowPress(e);
	}
    }

    @Override
    public boolean onSingleTapUp(MotionEvent e)
    {
	if (onGestureListener != null)
	{
	    onGestureListener.onSingleTapUp(e);
	}
	return false;
    }

    public boolean isLongpressEnabled()
    {
	return gestureDetector.isLongpressEnabled();
    }

    public void setIsLongpressEnabled(boolean isLongpressEnabled)
    {
	gestureDetector.setIsLongpressEnabled(isLongpressEnabled);
    }

    public OnGestureListener getOnGestureListener()
    {
	return onGestureListener;
    }

    private void setOnGestureListener(OnGestureListener onGestureListener)
    {
	this.onGestureListener = onGestureListener;
    }
}
